home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / amiga / ixmlb920.lha / stdio_2 / rcs / setvbuf.c,v < prev    next >
Text File  |  1992-08-09  |  4KB  |  159 lines

  1. head    1.2;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.2
  10. date    92.08.09.21.04.42;    author amiga;    state Exp;
  11. branches;
  12. next    1.1;
  13.  
  14. 1.1
  15. date    92.06.08.15.10.10;    author mwild;    state Exp;
  16. branches;
  17. next    ;
  18.  
  19.  
  20. desc
  21. @initial checkin
  22. @
  23.  
  24.  
  25. 1.2
  26. log
  27. @paranoia
  28. @
  29. text
  30. @/*-
  31.  * Copyright (c) 1990 The Regents of the University of California.
  32.  * All rights reserved.
  33.  *
  34.  * This code is derived from software contributed to Berkeley by
  35.  * Chris Torek.
  36.  *
  37.  * Redistribution and use in source and binary forms, with or without
  38.  * modification, are permitted provided that the following conditions
  39.  * are met:
  40.  * 1. Redistributions of source code must retain the above copyright
  41.  *    notice, this list of conditions and the following disclaimer.
  42.  * 2. Redistributions in binary form must reproduce the above copyright
  43.  *    notice, this list of conditions and the following disclaimer in the
  44.  *    documentation and/or other materials provided with the distribution.
  45.  * 3. All advertising materials mentioning features or use of this software
  46.  *    must display the following acknowledgement:
  47.  *    This product includes software developed by the University of
  48.  *    California, Berkeley and its contributors.
  49.  * 4. Neither the name of the University nor the names of its contributors
  50.  *    may be used to endorse or promote products derived from this software
  51.  *    without specific prior written permission.
  52.  *
  53.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  54.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  55.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  56.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  57.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  58.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  59.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  60.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  61.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  62.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  63.  * SUCH DAMAGE.
  64.  */
  65.  
  66. #if defined(LIBC_SCCS) && !defined(lint)
  67. static char sccsid[] = "@@(#)setvbuf.c    5.2 (Berkeley) 2/1/91";
  68. #endif /* LIBC_SCCS and not lint */
  69.  
  70. #define KERNEL
  71. #include "ixemul.h"
  72.  
  73. #include <stdio.h>
  74. #include <stdlib.h>
  75. #include "local.h"
  76.  
  77. /*
  78.  * Set one of the three kinds of buffering, optionally including
  79.  * a buffer.
  80.  */
  81. setvbuf(fp, buf, mode, size)
  82.     register FILE *fp;
  83.     char *buf;
  84.     register int mode;
  85.     register size_t size;
  86. {
  87.  
  88.     /*
  89.      * Verify arguments.  The `int' limit on `size' is due to this
  90.      * particular implementation.
  91.      */
  92.     if (!fp || (mode != _IOFBF && mode != _IOLBF && mode != _IONBF) ||
  93.         (int)size < 0)
  94.         return (EOF);
  95.  
  96.     /*
  97.      * Write current buffer, if any; drop read count, if any.
  98.      * Make sure putc() will not think fp is line buffered.
  99.      * Free old buffer if it was from malloc().  Clear line and
  100.      * non buffer flags, and clear malloc flag.
  101.      */
  102.     (void) __sflush(fp);
  103.     fp->_w = fp->_r = 0;
  104.     fp->_lbfsize = 0;
  105.     if (fp->_flags & __SMBF)
  106.         free((void *)fp->_bf._base);
  107.     fp->_flags &= ~(__SLBF|__SNBF|__SMBF);
  108.  
  109.     /*
  110.      * Now put back whichever flag is needed, and fix _lbfsize
  111.      * if line buffered.  Ensure output flush on exit if the
  112.      * stream will be buffered at all.
  113.      */
  114.     switch (mode) {
  115.  
  116.     case _IONBF:
  117.         fp->_flags |= __SNBF;
  118.         fp->_bf._base = fp->_p = fp->_nbuf;
  119.         fp->_bf._size = 1;
  120.         break;
  121.  
  122.     case _IOLBF:
  123.         fp->_flags |= __SLBF;
  124.         fp->_lbfsize = -size;
  125.         /* FALLTHROUGH */
  126.  
  127.     case _IOFBF:
  128.         /* no flag */
  129. /*        __cleanup = _cleanup;    */
  130.         fp->_bf._base = fp->_p = (unsigned char *)buf;
  131.         fp->_bf._size = size;
  132.         break;
  133.     }
  134.  
  135.     /*
  136.      * Patch up write count if necessary.
  137.      * Only (!) if we already have a buffer !
  138.      */
  139.     if ((fp->_flags & __SWR) && fp->_bf._base)
  140.         fp->_w = (fp->_flags & (__SLBF|__SNBF)) ? 0 : size;
  141.  
  142.     return (0);
  143. }
  144. @
  145.  
  146.  
  147. 1.1
  148. log
  149. @Initial revision
  150. @
  151. text
  152. @d74 1
  153. a74 1
  154.     fp->_r = 0;
  155. d111 1
  156. a111 1
  157.         fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : size;
  158. @
  159.